﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.CommunityToolkit.Extensions;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace KursachApp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class UsersPage : ContentPage
    {
        public UsersPage()
        {
            InitializeComponent();
        }

        private async void SaveFriend(object sender, EventArgs e)
        {

            if (tb1.Text != null && tb2.Text != null && tb3.Text != null && tb4.Text != null &&tb5.Text != null && tb6.Text != null && tb7.Text != null && tb8.Text != null )
            {
            var user = (Users)BindingContext;
            if (!String.IsNullOrEmpty(user.Name))
            {
                await App.Database.SaveItemAsync(user);
            }
            await this.Navigation.PopAsync();
                await this.DisplayToastAsync("Успешно сохранено", 2000);
            }
            
            else
            {
                await this.DisplayToastAsync("Заполнены не все поля", 2000);
            }

            
        }

        private async void DeleteFriend(object sender, EventArgs e)
        {
            var user = (Users)BindingContext;
            await App.Database.DeleteItemAsync(user);
            await this.Navigation.PopAsync();
            await this.DisplayToastAsync("Успешно удалено", 2000);
        }

        private async void Cancel(object sender, EventArgs e)
        {
            await this.Navigation.PopAsync();
        }
    }
}